import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      meta: {isHome: true},
      redirect: '/layout/homepages'
    },
    {
      path: '/login',
      meta: {islogin: true},
      component: () => import('@/view/login')
    },
    {
      path: '/layout',
      meta: {isHome: true},
      redirect: '/layout/homepages',
      component: () => import('@/components/layout'),
      children: [
        {
          path: '/layout/homepages',
          meta: {title: '首页管理', ischild: true},
          component: () => import('@/view/homepages'),
          children: [
            {
              path: '/layout/homepages/pages',
              meta: {title: '首页子级'},
              component: () => import('@/view/homepages/pages'),
              children: []
            }
          ]
        },
        {
          path: '/layout/video',
          meta: {title: '视频管理'},
          component: () => import('@/view/video'),
          children: []
        },
        {
          path: '/layout/my',
          meta: {title: '我的管理'},
          component: () => import('@/view/my'),
          children: []
        },
        {
          path: '/layout/friend',
          meta: {title: '朋友管理'},
          component: () => import('@/view/friend'),
          children: []
        },
        {
          path: '/layout/account',
          meta: {title: '账号管理'},
          component: () => import('@/view/account'),
          children: []
        }
      ]
    }
  ]
})
// router.beforeEach((to, from, next) => {
//   console.log(to, from)
//   const token = localStorage.getItem('token')
//   if (to.path !== '/login' && !token) {
//     next('/login')
//     return
//   }
//   if (token && to.path === '/login') {
//     // console.log('redirect')
//     next(from.path)
//     return false
//   }
//   next()
// })
export default router
